<template>
	<view class="content">
		<u-form-item label-position="top" label="详细内容">
			<u-input v-model="data.content" type="textarea" height="80" />
		</u-form-item>
		<u-form-item label-position="left" label="分类">
			<u-input disabled  v-model="typetext" placeholder="点击选择分类" type="text" @click="showtype" />
			<u-select v-model="show" :list="webset.types" @confirm="confirm"></u-select>
		</u-form-item>
		<u-form-item :border-bottom="false" label-position="top" prop="photo" label-width="150">
			<u-upload 
			width="160" height="160"
			 :action="action"
			  :file-list="data.fileList" 
			  :max-size="5 * 1024 * 1024"
				max-count="5" show-progress 
				@on-success="upload_success"
				 
				 @on-remove="remove"></u-upload>
		</u-form-item>
		
		<u-button type="error" :loading="loading" throttle-time="500" @click="add">发布</u-button>
		
		<foot></foot>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex'
	export default {
		props: {
			data: {
				type: Object,
				default: {}
			}
		},
		data() {
			return {
				typetext:"",
				loading:false,
				show: false,
				fileList: [],
				action: this.rooturl + "/index.php?class=base&act=upload",
				
				current: 0
			}
		},
		computed: {
			...mapState({
				webset: state => state.set.webset //等于value(){return this.$store.state.filter.value}//filter模块中state对象中的value值
			})
		},
	   mounted:function(){
	   	  this.typetext=this.data.typetext
	   },
		methods: {
			showtype(){
				this.show=true;
				uni.hideKeyboard()
			},
              confirm(e){
				  this.data.cid=e[0].value;
				  this.typetext=e[0].label
				
			  },
			  upload_success(data1, index, lists, name){
			
			  	this.data.imgs.push(data1.src)
			  },
			  remove(index){
			  	
			  	this.data.imgs.splice(index,1)
			  	console.log(this.data.imgs,1)
			  },
			  add() {
				  
				  if (this.data.content=="" || this.data.content == null){
				  	   this.msg("帖子内容不能为空");return
				  }
				  if (this.data.cid=="" || this.data.cid == null){
				  	   this.msg("请选择分类");return
				  }
				  delete this.data.typetext
				  this.data['status']=1;
				  let user=uni.getStorageSync("user")  
				  if (this.data.imgs)
				      this.data.imgs.join(",");
				   delete this.data.fileList;
				    this.$u.post('index.php?class=tie&act=addedi', this.data).then(res => {
					  if (res.code==0){
						
									  this.msg("提交成功，待审核");
									  this.jump("/pages/user/tie")
								  }else{
									  this.msg(res.msg)
								  }
				
				});
			  }
		}
	}
</script>

<style>
	.content {
		padding: 20rpx;
	}
</style>
